 var table ,form ,laypage ,layer ,element ,laydate ,upload,index1 //时间组件
$(function(){
	 layui.use(['table','form','laypage','layer', 'element', 'laydate','upload'], function(){
         table = layui.table;
         form=layui.form;
         laypage = layui.laypage ;//分页
         layer = layui.layer ;//弹层
         element = layui.element; //元素操作
         laydate = layui.laydate; //时间组件 
         upload = layui.upload;
         var hid = getQueryString("id");
         dictPublicfun();
     //附件列表示例
       var demoListView = $('#demoList'),
       uploadListIns = upload.render({
           elem: '#testList',
	         // ,url: 'https://httpbin.org/post' //改成您自己的上传接口
	         accept: 'file',
	         multiple: true,
	         auto: false,
	         bindAction: '#testListAction',
	         choose: function(obj){   
	            var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
	            //读取本地文件            
	            obj.preview(function(index, file, result){               
	                var formData = new FormData();
	                formData.append('myFile',file); // 固定格式
	                var tishi = layer.open({
		                    title: false
		                    ,closeBtn: 0
		                    ,shadeClose: false
		                    ,area: ['130px', '70px']
		                    ,type: 1
		                    ,content: '附件上传中...'
	                }); 
	                $.ajax({
	                      url:'/equipment/uploadEquipment.do',//后台接收数据地址
	                      headers: setHeader(),
	                      data:formData,
	                      type: "POST",
	                      async:false,//请求类型
	                      dataType: "json",
	                      cache: false,   //上传文件无需缓存
	                      processData: false,  //用于对data参数进行序列化处理 这里必须false
	                      contentType: false,
	                      success:function(res){
	                       if(res.status==200){
	                    	   var tr = $(['<tr id="upload-'+ index +'">'
					   			                ,'<td><span class="filename">'+ file.name +'</span><input type="hidden" class="enclosure" value="'+res.resultData.path+'"></td>'
					   			                ,'<td>'       
					   			                   ,'<a href="javascript:; return false"  class="layui-btn layui-btn-xs layui-btn-danger demo-delete" filelistid="">删除</a>'
					   			                ,'</td>'
					   			              ,'</tr>'].join(''));
	                    	   //删除
	         	              tr.find('.demo-delete').on('click', function(){
//	         	                delete files[index]; //删除对应的文件
//	         	                tr.remove();
	         	            	 delectte(this,res.resultData.path)  
	         	                uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
	         	              });              
	         	              demoListView.append(tr);
	                       }else{
	                           layer.msg(res.resultMsg, {icon: res.icon});
	                       } 
	                       layer.close(tishi); 
	                      },
	                      failure: function (res) {
	                        
	                      }
	                   })                                        	             
	            });
	          }
	          ,done: function(res, index, upload){
	        	  
	          }
	    });
    	var questData = {"id": hid};
 	  	$.ajax({
	           url: "/equipmentFault/getOneEquipmentFault.do",               //请求地址
	           type: "POST",              //请求类型
	           data:formatParam(questData),              //请求数据
	           timeout: 200000,                //请求超时时间(毫秒)
	           headers: setHeader(),
	           success:function(res){         //请求成功
	        	   if(res.status == 200) {
	        		    var num=res.resultData;
	        		    var file=num.listFile;
	        		    $("#id").val(hid); 
	        		    var codeData=num.equipmentName+"("+num.equipmentCode+")";
	        		    $("#faultequipmentId").val(codeData); 
	        		    var shehename="";
	    				if(num.state==1){//待处理
		            		shehename='color:#eca607'
		            	}else if(num.state==2){//已处理
		            		shehename='color:#5FB878'
		            	}else if(num.state==3){	//为解决           		
		            		shehename='color:#ec0707'
		            	}
  	    				$("#faultstate").val(num.stateZh); 	
  	    				$("#faultstate").attr("style",shehename);
  	    				$("#faultdescribe").val(num.describe); 
  	    				$("#faultremarks").val(num.remarks);
  	    				$("#handleDescribe").val(num.handleDescribe); 
	    				//附件
                        if(file.length>0){
                    		table.render({
                    		    elem: '#faultfilelist',
                    		    height:258,		   
                    		    text: {
                    			    none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                    			  },
                    			method: 'post',  
                    			loading: true,
                    		    headers: setHeader(),
                    		    data:file,
                    		    page: false, //开启分页
                    		    cols: [[    //表头
                    		      {field: 'id', title: 'ID',   align:'center',hide:true,width:5},
                    		      {field: 'xuhao', title: '序号',  align:'center', type:'numbers',width:'20%',},	
                    		      {field: '', title: '文件',  align:'left',width:'80%',
                    		    	  templet: function(data){
        	     			    		  if(data.addressZh==null){
        	     			    			 return ""
        	     			    		  }else if(data.type==1){
        	     			    			 return "<a class='lookurladdress' lay-event='lookimg' title='图片查看'   href='javascript:void(0);'>"+
				     					    		        "<ul id='"+data.addressZh+"'>"+
				    										"<li><img data-original='"+data.addressZh+"' src='"+data.addressZh+"'  alt='图片'  style='width:100%;height:100%'/></li>"+
				    									 "</ul>"+
				    								  "</a>"	        	     		
        			                          form.render();//需要渲染一下
        	     			    		  }else if(data.type==5){
        	     			    			  return '<div class="layui-btn-group">'+         						          
        				          			              '<a title="视频播放"  href="javascript:;" onclick="videoclick(\''+data.addressZh+'\')" class="layui-btn layui-btn-sm">'+data.address+'</a>'+ 
	        					          		      '</div>'   
					                          form.render();//需要渲染一下
			     			    		  }else{
        	     			    		       return '<a class="layui-btn layui-btn-xs layui-btn-normal" title="文档下载"  href="/equipmentFault/download.do?filePath='+data.address+'" download="文件下载">'+data.address+'</a>';
        	     			    		      form.render();//需要渲染一下
			     			    		  } 	     			            	   
        	     			           }  
                    		      }
                    		    ]],
                    		    done: function (res) {
                    		    	 
                                }
                    		});
                    		 permissionFUN()//功能按钮权限
                           }
	    					form.render();
		  				}else if(res.status == 666){
		  					TIMEOUT(); 
		  		        }else{          	  				    
		  					layer.msg(res.resultMsg, {icon: res.icon});
		  				}	  				      
	           }
 	  		})
 	  	 table.on('tool(test)', function (obj) {
 			form.render();//需要渲染一下
 	        var data = obj.data;
 	        if(obj.event === 'lookimg'){ //图片查看
 	           	 var viewer = new Viewer(document.getElementById(data.addressZh), {
 		     			url: 'data-original',
 		     			navbar: false
 		     		});
 			 }    
 			form.render();//需要渲染一下	   
 	    });
	});
})

//视屏点击查看
	 function videoclick(addressZh) {
	//视频播放
		$("body").find("#my-video").remove();
    var $content='<video id="my-video" class="video-js vjs-big-play-centered vjs-fluid" controls preload="auto" poster="" style="width:100%;height:100%" data-setup="{}">'+
           '<source src="'+addressZh+'" type="video/mp4">'+
           '<source src="'+addressZh+'" type="video/webm">'+
           '<source src="'+addressZh+'" type="video/ogg">'+
        '</video>';
    	layer.open({
             type: 1,
             area: ['800px', '500px'],
             fix: false, //不固定
             maxmin: true,
             shadeClose: true,
             tipsMore: true,
             shade:0.4, //遮罩层
             title: ['视频播放','background:#1E9FFF;color:#fff'],
             content:$content
         }); 
      //设置中文
      videojs.addLanguage('zh-CN', {
       "Play": "播放",
       "Pause": "暂停",
       "Current Time": "当前时间",
       "Duration": "时长",
       "Remaining Time": "剩余时间",
       "Progress": "进度",
       "Fullscreen": "全屏",
       "Non-Fullscreen": "退出全屏",
       "Close": "关闭",
       "Video Player": "视频播放器",
       "Replay": "重播",
       "Progress Bar": "进度小节",
       "Volume Level": "音量"
     });
    var myPlayer = videojs('my-video', { fluid: true }, function () {
   	});
} 